/**
 *
 */
package de.cbf.cam.dsa.services.impl.rcp_provider;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import de.cbf.cam.dsa.rcp.model.entities.RaceDSA;
import de.cbf.cam.dsa.services.impl.rcp_provider.extension.interfaces.IRCPPersisterRace;
import de.cbf.cam.dsa.services.interfaces.rcp_provider.IServiceDSAProviderRace;
import de.cbf.cam.dsa.services.interfaces.rcp_provider.exceptions.EntityNotFoundException;
import de.cbf.util.db.interfaces.exceptions.EntityLoadException;
import de.cbf.util.db.interfaces.exceptions.EntitySaveException;
import de.cbf.util.uuidheader.entities.UUIDHeader;

/**
 * @author Alti
 *
 */
public class ProviderRace implements IServiceDSAProviderRace {
	private static final Log logger = LogFactory.getLog(ProviderRace.class);
	protected IRCPPersisterRace persister;

	public ProviderRace() {
		super();
	}


	@Override
	public UUIDHeader getEntityByItsID(UUID id) throws EntityNotFoundException {
		RaceDSA race;
		try {
			race = persister.loadRace(id);
		} catch (EntityLoadException e) {
			throw new EntityNotFoundException("RaceDSA NOT found,id: "+id,e);
		}
		return race;
	}

	public List<RaceDSA> provideAllRaces(){
		List<RaceDSA> resultList = new ArrayList<RaceDSA>();
		try {
			resultList.addAll(persister.loadAllRaces());
		} catch (EntityLoadException e) {
			logger.error(e);
		}
		return resultList;
	}

	@Override
	public void persistRace(RaceDSA entity) {
		try {
			persister.saveRace(entity);
		} catch (EntitySaveException e) {
			logger.error(e);
		}
	}

	@Override
	public String getName() {
		return "Race provider via "+persister.getName();
	}

	public IRCPPersisterRace getPersister() {
		return persister;
	}
	public void setPersister(IRCPPersisterRace persister) {
		this.persister = persister;
	}



}
